﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace can.Model
{
    /// <summary>
    /// PLC结果类 可以隐式转换为bool 值为true表示成功 false表示失败
    /// </summary>
    public class PLCResult
    {
        internal PLCResult([CallerMemberName] string? caller = null)
        {
            Caller = caller ?? "Unknown";
        }

        public Exception? Exception { get; internal set; }

        public readonly string Caller;

        public int Layer { get; internal set; } = -1;

        public HashSet<int> Layers { get; internal set; }

        public PLCErrorType ErrorType { get; internal set; } = PLCErrorType.None;

        private bool NoBIB => Layers == null && Layer == -1;

        public static implicit operator bool(PLCResult result)
        {
            return result.Exception == null;
        }
    }
    
}
